/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.games.esmi.ieat.indicatorrelations;

import com.invient.vaadin.charts.InvientCharts;
import com.invient.vaadin.charts.InvientCharts.DecimalPoint;
import com.invient.vaadin.charts.InvientCharts.SeriesType;
import com.invient.vaadin.charts.InvientCharts.XYSeries;
import com.invient.vaadin.charts.InvientChartsConfig;
import com.invient.vaadin.charts.InvientChartsConfig.GeneralChartConfig.Margin;
import com.invient.vaadin.charts.InvientChartsConfig.PieConfig;
import com.invient.vaadin.charts.InvientChartsConfig.PieDataLabel;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Table;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import eu.games.esmi.ieat.indicatorrelations.data.AssociationRule;
import eu.games.esmi.ieat.indicatorrelations.data.Cluster;
import eu.games.esmi.ieat.indicatorrelations.data.Legenda;
import java.util.LinkedHashSet;

/**
 *
 * @author user
 */
public class ClusteringAnalysisTab extends Panel {
    
    private Table table = new Table();
    private Table legenda = new Table();
    
    public ClusteringAnalysisTab() {
        super();
        init();
    }
    
    public void init() {
        
        HorizontalLayout hl = new HorizontalLayout();
        hl.setSpacing(true);
        
        VerticalLayout v1 = new VerticalLayout();
            v1.addComponent(new Label("Clusters"));

            final BeanItemContainer<Cluster> tableContainer = new BeanItemContainer<Cluster>(Cluster.class);
            table.setContainerDataSource(tableContainer);
            table.setWidth(240, Sizeable.UNITS_PIXELS);
            table.setVisibleColumns(new Object[] { "name", "percentage" });
    //        table.addItem(new AssociationRule("CPU usage s1 > CPU usage s2", "", ""));
    //        table.addItem(new AssociationRule("red & green", "0.9", "0.4"));

            //TODO PROVA!!!
            //Tabs.INSTANCE.correlationAnalysisTab = this;

            v1.addComponent(table);
        hl.addComponent(v1);
        
        VerticalLayout v2 = new VerticalLayout();
            v2.addComponent(new Label("Legenda"));

            final BeanItemContainer<Legenda> legendaContainer = new BeanItemContainer<Legenda>(Legenda.class);
            legenda.setContainerDataSource(legendaContainer);
            legenda.setWidth(640, Sizeable.UNITS_PIXELS);
            legenda.setVisibleColumns(new Object[] { "centroid", "values" });
    //        table.addItem(new AssociationRule("CPU usage s1 > CPU usage s2", "", ""));
    //        table.addItem(new AssociationRule("red & green", "0.9", "0.4"));

            //TODO PROVA!!!
            //Tabs.INSTANCE.correlationAnalysisTab = this;

            v2.addComponent(legenda);
        hl.addComponent(v2);

        this.addComponent(hl);
//        PieConfig pieCfg1 = new PieConfig();
//        pieCfg1.setAnimation(true);
//        pieCfg1.setDataLabel(new PieDataLabel(true));
//        //pieCfg1.setColor(new RGB(100, 100, 100));
//        //pieCfg1.getDataLabel().setConnectorColor(new RGB(100, 100, 100));
//        pieCfg1.setAllowPointSelect(true);
//        pieCfg1.setShowInLegend(true);
//
//        XYSeries series1 = new XYSeries("Browsers", SeriesType.PIE, pieCfg1);
//        LinkedHashSet<DecimalPoint> points1 = new LinkedHashSet<DecimalPoint>();
//
//        DecimalPoint point1 = new DecimalPoint(series1, "Firefox", 40.0);
//        //point1.setConfig(new PointConfig(new RGB(230, 0, 0)));
//        points1.add(point1);
//        point1 = new DecimalPoint(series1, "Chrome", 30.0);
//        //point1.setConfig(new PointConfig(new RGB(0, 230, 0)));
//        points1.add(point1);
//        point1 = new DecimalPoint(series1, "IE", 13.0);
//        //point1.setConfig(new PointConfig(new RGB(0, 0, 230)));
//        points1.add(point1);
//        point1 = new DecimalPoint(series1, "Safari", 20.0);
//        //point1.setConfig(new PointConfig(new RGB(230, 230, 0)));
//        points1.add(point1);
//        point1 = new DecimalPoint(series1, "Other", 3.0);
//        //point1.setConfig(new PointConfig(new RGB(230, 0, 230)));
//        points1.add(point1);
//
//        series1.setSeriesPoints(points1);
//
//        InvientChartsConfig chartConfig = new InvientChartsConfig();
//        chartConfig.getGeneralChartConfig().setType(SeriesType.PIE);
//        chartConfig.getSubtitle().setText("Source: PROCESSBASSE BPMS");
//
//        chartConfig.getGeneralChartConfig().setMargin(new Margin());
//        chartConfig.getGeneralChartConfig().getMargin().setTop(50);
//        chartConfig.getGeneralChartConfig().getMargin().setRight(0);
//        chartConfig.getGeneralChartConfig().getMargin().setBottom(0);
//        chartConfig.getGeneralChartConfig().getMargin().setLeft(0);
//        chartConfig.setLegend(new InvientChartsConfig.Legend(true));
//        chartConfig.getTitle().setText("PieChart Demo");
//
//        chartConfig.getTooltip().setFormatterJsFunc(
//                "function() {"
//                + " return '<b>'+ this.series.name +'</b><br/>'+ "
//                + "     this.point.name +': '+ this.y; " + "}");
//        
//        InvientCharts ich2 = new InvientCharts(chartConfig);
//        ich2.addSeries(series1);
//        
//        ich2.setWidth("100%");
//        ich2.setHeight("100%");
//        addComponent(ich2);
        
        
        //vl.addComponent(new IndicatorChart());
        
        //this.addComponent(vl);
        
        
        
        
        //TextArea area = new TextArea("Data Mining result", Miner.demo());
        //this.addComponent(area);
    }
    
    public void addClusterToTable(String name, double percentage) {
        table.addItem(new Cluster(name, percentage+"%"));
    }

    void clearLegendOfZelda() {
        table.removeAllItems();
        legenda.removeAllItems();
    }

    public void addGamesToLegenda(String indicators, Object description) {
        legenda.addItem(new Legenda(indicators, description.toString()));
    }
}
